@extends('layouts._app')
@section('content')
    <body>
    <div class="wrap-container">
        <div class="column-content-detail">
            {!! Form::open(['route' => 'blog.comment.index','class'=>'layui-form','method'=>'get']) !!}
            <div class="layui-form-item">
                <div class="layui-inline tool-btn">
                    <a class="layui-btn layui-btn-small layui-btn-primary" id='email-refresh-btn'
                       href="{{route('blog.comment.index')}}" data-title='刷新'>
                        <i class="layui-icon">&#x1002;</i>
                    </a>
                    <button class="layui-btn layui-btn-small layui-btn-danger delBtn hidden-xs">
                        <i class="layui-icon">&#xe640;</i>
                    </button>
                </div>
                <div class="layui-inline">
                    {!! Form::search('title',"{$request['title']}",['class'=>'layui-input','placeholder'=>'请输入文章标题']) !!}
                </div>
                {!! Form::submit('搜索',['class'=>'layui-btn layui-btn-normal','lay-submit'=>'search']) !!}
                <div class="layui-inline" style="float: right;">
                    <select id="change_category" lay-filter="category" lay-search data-id="comments">
                        <option selected>下载</option>
                        <option>.txt</option>
                        <option>.xlsx</option>
                    </select>
                </div>
            </div>
            {!! Form::close() !!}
            @include('layouts._flash')
            <div class="layui-form" id="table-list">
                <table class="layui-table">
                    <tr>
                        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                        <th>文章ID</th>
                        <th>文章标题</th>
                        <th>用户名</th>
                        <th>@用户名</th>
                        <th>评论内容</th>
                        <th>过滤的内容</th>
                        <th>过滤之后的内容</th>
                        <th>评论时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    @foreach($comment as $value)
                        <tr class="parent collapsed">
                            <td><input type="checkbox" name="del" lay-skin="primary" data-id="{{$value->id}}"></td>
                            <td title="{{$value->article_id}}">{{sub($value->article_id,20)}}</td>
                            <td title="{{$value->article->title}}">{{sub($value->article->title,20)}}</td>
                            <td title="{{$value->user->name}}">{{sub($value->user->name,20)}}</td>
                            <td>@if($value->clientName)
                                    @ {{$value->clientName->name}}
                                @endif</td>
                            <td title="{{$value->content}}">{{sub($value->content,20)}}</td>
                            <td title="{{$value->filter}}">{{sub($value->filter,20)}}</td>
                            <td title="{{$value->filter_content}}">{{sub($value->filter_content,20)}}</td>
                            <td title="{{$value->created_at}}">{{sub($value->created_at,20)}}</td>
                            <td title="@if($value->is_show == 1) 显示 @else 隐藏 @endif">
                                <a class="layui-btn layui-btn-mini layui-btn-normal"
                                   href="{{route('blog.comment.status',$value->id)}}"
                                   data-method="delete"
                                   data-token="{{csrf_token()}}"
                                   data-confirm="@if($value->is_show == 1) 确认禁用? @else 确认启用? @endif">
                                    @if($value->is_show == 1) 显示 @else 隐藏 @endif
                                </a>
                            </td>
                            <td>
                                <div class="layui-inline">
                                    <a class="layui-btn layui-btn-small layui-btn-danger"
                                       href="{{route('blog.comment.destroy',$value->id)}}"
                                       data-method="delete" title="文章删除"
                                       data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                        <i class="layui-icon">&#xe640;</i></a>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                </table>
                <!--tp分页-->
                <div class="page-wrap">
                    <p style="float: left;">注 : 共 {{$comment->total()}} 条记录</p>
                    {{ $comment->links() }}
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('static/admin/layui/layui.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('static/admin/js/common.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/jquery.min.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/destroy.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/common.js')}}" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use(['jquery', 'dialog'], function () {
            var $ = layui.jquery;
            var dialog = layui.dialog;
            //顶部批量删除
            $('.delBtn').click(function () {
                var ids = [];
                $("input[name='del']:checked").each(function (i) {
                    ids[i] = $(this).data('id');
                });
                if (ids.length == 0) {
                    layer.msg('请选择要删除的', {icon: 5, time: 3000});
                    return false;
                }
                dialog.confirm({
                    message: '您确定要删除选中项',
                    success: function () {
                        $.ajax({
                            type: 'POST',
                            url: '{{route('blog.comment.delete')}}',
                            data: {id: ids, filter: true},
                            dataType: "json",
                            beforeSend: function () {
                                layer.load(1, {
                                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                                });
                            },
                            complete: function (XHR) {
                                XHR = null;
                            },
                            error: function (xhr) {//获取ajax的错误信息
                                layer.alert(xhr.responseText, "Failed", function () {
                                    layer.closeAll();
                                });
                            },
                            success: function (res) {
                                layer.closeAll();
                                if (res.code == 403) {
                                    layer.msg(res.msg, {icon: 4, time: 3000})
                                    return false;
                                }
                                if (res.code != 200) {
                                    layer.msg(res.msg, {icon: 5, time: 3000})
                                    return false;
                                }
                                layer.msg(res.msg, {icon: 1, time: 3000}, function () {
                                    window.location.reload();
                                });
                            }
                        })
                    },
                    cancel: function () {
                        return false;
                    }
                })
                return false;

            }).mouseenter(function () {

                dialog.tips('批量删除', '.delBtn');

            })
            layui.use(['form'], function () {
                var form = layui.form();

                form.on('select(category)', function (e) {
                    if (e.value == '下载') {
                        return false;
                    }
                    /**
                     * 写入文件下载
                     * @param id
                     */
                    var table = $("#change_category").data('id');
                    var ext = e.value;
                    dialog.confirm({
                        message: '这可能会耗费很长时间！是否继续',
                        success: function () {
                            window.open('{{route('TextFile')}}' + '?table=' + table + '&ext=' + ext, '_parent');
                            window.location.reload();
                        },
                    });
                });
                //栏目展示隐藏
                $('.showSubBtn').on('click', function () {
                    var _this = $(this);
                    var id = _this.attr('data-id');
                    var parent = _this.parents('.parent');
                    var child = $('.child-node-' + id);
                    var childAll = $('tr[parentid=' + id + ']');
                    if (parent.hasClass('collapsed')) {
                        _this.html('-');
                        parent.addClass('expanded').removeClass('collapsed');
                        child.css('display', '');
                    } else {
                        _this.html('+');
                        parent.addClass('collapsed').removeClass('expanded');
                        child.css('display', 'none');
                        childAll.addClass('collapsed').removeClass('expanded').css('display', 'none');
                        childAll.find('.showSubBtn').html('+');
                    }
                })
                form.render();
            });

        })
    </script>
    </body>
@endsection
